package com.lyd.generic.demo;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * @Author:lyd
 **/
public class Test {
    public static void main(String[] args) {

        //泛型通配符下限示例 (Comparator<? super E> comparator
        TreeSet<Cat> cats = new TreeSet<>(new Comparator2());
        cats.add(new Cat("tom", 18));
        cats.add(new Cat("jerry", 8));
        cats.add(new Cat("jim", 15));
        cats.add(new Cat("stark", 6));
        for (Cat cat : cats) {
            System.out.println(cat);
        }
    }
}

class Comparator1 implements Comparator<Animal>{

    @Override
    public int compare(Animal o1, Animal o2) {
        return o1.getName().compareTo(o2.getName());
    }

}

class Comparator2 implements Comparator<Cat>{

    @Override
    public int compare(Cat o1, Cat o2) {
        return o1.getAge()-o2.getAge();
    }
}

class Comparator3 implements Comparator<MiniCat>{
    @Override
    public int compare(MiniCat o1, MiniCat o2) {
        return o1.getLevel() - o2.getLevel();
    }
}